import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import weibull_min
import numpy as np

df1 = pd.read_csv("050525a100525.csv", sep=";", decimal=",")
df2 = pd.read_csv("171125a221125.csv", sep=";", decimal=",")

v1 = df1["velocidad"]
dir1 = df1["direccion"]
E1 = df1["energia"]

v2 = df2["velocidad"]
dir2 = df2["direccion"]
E2 = df2["energia"]

#print(v1.describe())

shape, loc, scale = weibull_min.fit(v1, floc=0)

k = shape
lam = scale

print("k (05/05/25 - 10/05/25) =", k)
print("lambda (05/05/25 - 10/05/25) =", lam)

x = np.linspace(0, max(v1), 100)
pdf = weibull_min.pdf(x, k, scale=lam)

plt.hist(v1, bins=20, density=True, alpha=0.6)
plt.plot(x, pdf)
plt.xlabel("Velocidad (m/s)")
plt.ylabel("Frecuencia relativa")
plt.title("Histograma y ajuste Weibull (05/05/25-10/05/25)")
plt.show()

shape, loc, scale = weibull_min.fit(v2, floc=0)

k2 = shape
lam2 = scale

print("k (17/11/25 - 22/11/25) =", k2)
print("lambda (17/11/25 - 22/11/25) =", lam2)

x2 = np.linspace(0, max(v2), 100)
pdf2 = weibull_min.pdf(x2, k2, scale=lam)

plt.hist(v2, bins=20, density=True, alpha=0.6)
plt.plot(x2, pdf2)
plt.xlabel("Velocidad (m/s)")
plt.ylabel("Frecuencia relativa")
plt.title("Histograma y ajuste Weibull (05/05/25-10/05/25)")
plt.show()